package com.example.asus.a1211;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.azoft.carousellayoutmanager.CarouselLayoutManager;
import com.azoft.carousellayoutmanager.CarouselZoomPostLayoutListener;
import com.azoft.carousellayoutmanager.CenterScrollListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    RecyclerView ry;
    List<String> mDatas=new ArrayList<>(  );
    MsgAdapter mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();
        ry= (RecyclerView) findViewById(R.id.id_re);
        //ry.setLayoutManager(new LinearLayoutManager(this));

        final CarouselLayoutManager layoutManager=new CarouselLayoutManager(CarouselLayoutManager.HORIZONTAL);
        ry.setLayoutManager( layoutManager );
        ry.setHasFixedSize(true);
        ry.addOnScrollListener(new CenterScrollListener());
        //ry.setAdapter( new MsgAdapter() );
        ry.setAdapter(mAdapter=new MsgAdapter());
    }
    protected void initData(){
        mDatas=new ArrayList<String>();
        for (int i='A';i<'z';i++){
            mDatas.add(""+(char) i);
        }
    }
    class MsgAdapter extends RecyclerView.Adapter<MsgAdapter.MyViewHolder> {
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int ViewType) {
            MyViewHolder holder=new MyViewHolder(LayoutInflater.from(MainActivity.this).
                    inflate(R.layout.item,parent,false));
            return holder;
        }
        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
            if (position==0){
                holder.itemView.setBackgroundColor(Color.parseColor("#ff0000"));
            }
            if (position==1){
                holder.itemView.setBackgroundColor(Color.parseColor("#00ff00"));
            }
            if (position==2){
                holder.itemView.setBackgroundColor(Color.parseColor("#0000ff"));
            }

        }

        @Override
        public int getItemCount() {
            return mDatas.size();
        }
        class MyViewHolder extends RecyclerView.ViewHolder{
            TextView textView;
            public MyViewHolder(@NonNull View itemView) {
                super( itemView );
            }
        }
    }
}
